package com.vitabuybuy.tv.network

import com.library.common.net.NetUrl
import com.vitabuybuy.tv.dto.CouponCenterDto
import com.vitabuybuy.tv.dto.MyCouponDto


import rxhttp.IAwait
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

/**
 * 作者：SimGa
 * 日期：2020/12/29
 * 时间：15:41
 * 包名：com.vitabuybuy.tv.network
 */
object CouponCenterRepository {


    fun getCouponsList(
        map: HashMap<String, Any?>,
        pageNumber: Int
    ): IAwait<MutableList<CouponCenterDto>> {
        map["pageable"] = mapOf(
            Pair("page", pageNumber),
            Pair("size", 10)
        )
        return RxHttp.postJson(NetUrl.api_find_coupon_center_list)
            .addAll(map).toResponse()
    }

    fun saveACoupon(
        couponId: Int
    ): IAwait<String> {
        return RxHttp.postJson(NetUrl.api_save_a_coupon)
            .add("userCouponRecord",mapOf(Pair("coupon", mapOf(
                Pair("id",couponId)
            )))).toResponse()
    }

    fun getMyCouponsList(
        map: HashMap<String, Any>,
        pageNumber: Int
    ): IAwait<MutableList<MyCouponDto>> {
        map["pageable"] = mapOf(
            Pair("page", pageNumber),
            Pair("size", 10)
        )
        return RxHttp.postJson(NetUrl.api_my_usercoupons_list)
            .addAll(map).toResponse()
    }
}